﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using deckAnalyser.Support;

namespace deckAnalyser.Forms
{
  public partial class OptionsForm : Form
  {
    public OptionsForm()
    {
      InitializeComponent();
    }

    private void btnCancel_Click(object sender, EventArgs e)
    {
      DialogResult = DialogResult.Cancel;
      Close();
    }

    private void bntApply_Click(object sender, EventArgs e)
    {
      Options.Set("DefaultAuthor", tbAuthor.Text);
      Options.Set("DefaultCollection", cbCollection.SelectedItem as String);
      Options.Save();
      DialogResult = DialogResult.OK;
      Close();
    }

    private void OptionsForm_Activated(object sender, EventArgs e)
    {
      // Set the default author
      //
      tbAuthor.Text = Options.Get("DefaultAuthor", "");


      // Set the default collection
      //
      cbCollection.Items.Clear();
      DataTable dt = DBWrapper.GetDataTable("SELECT c.name AS 'Collection Name' FROM collections.collections c");
      foreach (DataRow row in dt.Rows)
        cbCollection.Items.Add(row["Collection Name"]);
      cbCollection.SelectedItem = Options.Get("DefaultCollection", "Default");  
    }

  }
}
